package algorithm;

public class TreeNodeTest3 {
    public static void main(String[] args) {
        TreeNode node = TreeUtil.buildNoTotalTree();
        System.out.println(pathSum(node, 11));
    }


    // 路径之和，给定一个二叉树根节点和数字，判断二叉树根节点到叶子节点是否有路径和等于指定数字
    private static boolean pathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null) {
            return root.data == targetSum;
        }
        return pathSum(root.left, targetSum - root.data)
                || pathSum(root.right, targetSum - root.data);
    }
}
